package com.woniu.dao;

import com.woniu.dto.ComplainDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface ComplainMapper {

    @Select("SELECT ss.id,ss.statecontext reason,ss.`status`,ss.reply_context context,so.starttime startTime,so.id orderId,\n" +
            "pu.nickname nickName,pu.mailbox mailBox,pu.sex FROM state_service ss LEFT JOIN service_order so ON ss.serviceid=so.id\n" +
            "INNER JOIN person_user pu ON pu.id=so.userid order by ss.id desc")
    List<ComplainDTO> findByPage(@Param("currentPage")Integer currentPage,@Param("pageSize")Integer pageSize);

    @Update("update state_service set status=1,reply_context=#{context} where id=#{id}")
    void addReply(@Param("id") Integer id, @Param("context") String context);

    @Select("select * from state_service where id=#{value}")
    ComplainDTO findById(Integer id);

    /*@Select("<script>"
            +"SELECT ss.id,ss.statecontext reason,ss.`status`,ss.reply_context context,so.starttime startTime,so.id orderId,\n" +
            "pu.nickname nickName,pu.mailbox mailBox,pu.sex FROM state_service ss LEFT JOIN service_order so ON ss.serviceid=so.id\n" +
            "INNER JOIN person_user pu ON pu.id=so.userid "
            + "<where>"
            + "<if test='userName !=null and userName !='''>"
            + "and pu.nickname like concat('%',#{userName},'%')"
            + "</if>"
            +"<if test='status !=null'>"
            +"and ss.status = #{status}"
            +"</if>"
            +"</where>"
            +"order by ss.id desc"
            +"</script>")*/
    List select(@Param("userName") String userName,@Param("status") Integer status);
}
